package test21.homeWork;

import java.io.*;

public class StreamUtils {
    //功能：将输入流转换成byte[]
    public static byte[] streamToByteArray(InputStream is) throws IOException {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();//创建输出流对象
        byte[] buf = new byte[1024];
        int leng = 0;
        while ((leng = is.read(buf)) != -1){
            bos.write(buf,0,leng);
        }
        byte[] array = bos.toByteArray();
        bos.close();
        return array;
    }
    //功能：将InputStream转换成String
    public static String streamToString(InputStream is) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
        StringBuilder stringBuilder = new StringBuilder();
        String line;
        while ((line = bufferedReader.readLine()) != null){
            stringBuilder.append(line+"\r\n");
        }
        return stringBuilder.toString();
    }
}
